<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set the default stream context</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.stream-context-get-params.html">« stream_context_get_params</a></li>
      <li style="float: right;"><a href="function.stream-context-set-option.html">stream_context_set_option »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.stream.html">Stream 函数</a></li>
    <li>Set the default stream context</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.stream-context-set-default" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_context_set_default</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_context_set_default</span> &mdash; <span class="dc-title">Set the default stream context</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stream-context-set-default-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_context_set_default</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>): <span class="type">resource</span></div>

  <p class="simpara">
   Set the default stream context which will be used whenever file operations
   (<span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>, <span class="function"><a href="function.file-get-contents.html" class="function">file_get_contents()</a></span>, etc...)
   are called without a context parameter. Uses the same syntax as
   <span class="function"><a href="function.stream-context-create.html" class="function">stream_context_create()</a></span>.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.stream-context-set-default-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       The options to set for the default context.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        <code class="parameter">options</code> must be an associative
        array of associative arrays in the format
        <code class="literal">$arr[&#039;wrapper&#039;][&#039;option&#039;] = $value</code>.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.stream-context-set-default-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the default stream context. 
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.stream-context-set-default-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="stream-context-set-default.example.basic">
    <p><strong>示例 #1 <span class="function"><strong>stream_context_set_default()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$default_opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'http'</span><span style="color: #007700">=&gt;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'method'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"GET"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'header'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"Accept-language:&nbsp;en\r\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Cookie:&nbsp;foo=bar"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'proxy'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"tcp://10.54.1.39:8000"<br />&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$default&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_set_default</span><span style="color: #007700">(</span><span style="color: #0000BB">$default_opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Sends&nbsp;a&nbsp;regular&nbsp;GET&nbsp;request&nbsp;to&nbsp;proxy&nbsp;server&nbsp;at&nbsp;10.54.1.39<br />&nbsp;*&nbsp;For&nbsp;www.example.com&nbsp;using&nbsp;context&nbsp;options&nbsp;specified&nbsp;in&nbsp;$default_opts<br />&nbsp;*/<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.stream-context-set-default-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.stream-context-create.html" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - 创建资源流上下文</span></li>
    <li class="member"><span class="function"><a href="function.stream-context-get-default.html" class="function" rel="rdfs-seeAlso">stream_context_get_default()</a> - Retrieve the default stream context</span></li>
    <li class="member">Listing of supported wrappers with context options (<a href="wrappers.html" class="xref">支持的协议和封装协议</a>).</li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>